#include <iostream>
#include <string>
#include <algorithm>

using std::cin;
using std::cout;
class Student
{
public:
	int id;
	std::string name;
	int finalExam;
	int estScore;
	char isLeader;
	char isWest;
	int article;
	int prize;
	bool operator<(const Student &oth) const
	{
		if (prize == oth.prize)
		{
			return id < oth.id;
		}
		else
		{
			return prize > oth.prize;
		}
	}
	void calc()
	{
		prize = 0;
		if (finalExam > 80 && article >= 1)
		{
			prize += 8000;
		}
		if (finalExam > 85 && estScore > 80)
		{
			prize += 4000;
		}
		if (finalExam > 90)
		{
			prize += 2000;
		}
		if (finalExam > 85 && isWest == 'Y')
		{
			prize += 1000;
		}
		if (estScore > 80 && isLeader == 'Y')
		{
			prize += 850;
		}
	}
	Student() = default; // 一定要加无参数构造函数！！！
	Student(int id,
			const std::string &name,
			int finalExam,
			int estScore,
			char isLeader,
			char isWest,
			int article)
	{
		this->name = name;
		this->finalExam = finalExam;
		this->estScore = estScore;
		this->isLeader = isLeader;
		this->isWest = isWest;
		this->article = article;
		calc();
	}
} stu[110];
int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n, total = 0;
	std::string name;
	int finalExam;
	int estScore;
	char isLeader;
	char isWest;
	int article;
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		cin >> name >> finalExam >> estScore >> isLeader >> isWest >> article;
		stu[i] = Student(i, name, finalExam, estScore, isLeader, isWest, article);
		total += stu[i].prize;
	}
	std::stable_sort(stu + 1, stu + n + 1); // 稳定排序！！！
	cout << stu[1].name << '\n'
		 << stu[1].prize << '\n'
		 << total;
}
